package com.googlecode.spreadit.util;


/**
 * This utility class provides a lean set of methods for string operations.
 * 
 * @author Markus L. Dechert (markus.dechert@googlemail.com)
 */
public abstract class StringUtil {

	/**
	 * Returns true if the passes string is null or contains only whitespace.
	 * 
	 * @param s
	 *            the string to check.
	 * @return <code>true</code>, if <code>null</code> or empty or only
	 *         whitespace.
	 */
	public static boolean isEmpty(String s) {
		return (s == null) || (s.trim().length() == 0);
	}

	public static String toCamelCase(String s) {
		char[] arr = s.toCharArray();
		char[] result = new char[arr.length];

		boolean nextToUpper = true;
		int res_i = 0;
		for (int si = 0; si < arr.length; si++) {
			if (arr[si] == '_') {
				nextToUpper = true;
			} else {
				result[res_i] = nextToUpper ? Character.toUpperCase(arr[si])
						: Character.toLowerCase(arr[si]);
				res_i++;
				nextToUpper = false;
			}
		}
		return String.copyValueOf(result, 0, res_i);
	}
}
